const apis = require("../../apis/request")
const app = getApp();
const utils = require('../../utils')
Page({
  data: {
    history: []
  },
  async onLoad(options) {
    const r = await utils.getOpenIdOrCode()
    const { data } = await apis.getHistory({
      ...r,
      status: 1,
      // openId: '_000TQs5oSuJ1Gn7Cua-u8f-a6FYG8DAJLDf',
      pageSize: 100,
    })
    this.setData({
      history: data.map(item => {

        return {
          ...item,
          date: this.formatDateToYYYYMMDDHHMMSS(new Date(item.createdAt))
        }
      })
    })
  },
  formatDateToYYYYMMDDHHMMSS(date) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  }
})